const app = getApp()
Page({
	data: {
		// 键盘
		provinceArr:["粤", "京", "津", "渝", "沪", "冀", "晋", "辽", "吉", "黑", "苏", "浙", "皖", "闽", "赣", "鲁", "豫", "鄂", "湘", "琼", "川", "贵", "云", "陕", "甘", "青", "蒙", "桂", "宁", "新", "藏", "使", "领", "警", "学", "港", "澳"],
		strArr:["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Q", "W", "E", "R", "T", "Y", "U", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "I", "V", "B", "N", "M"],
		hiddenPro:false, // 省份键盘
		hiddenStr:true, // 数字字母键盘
		carnum:'',
		ordinarynum:[],
		energycar:[],
		isOrdinary:true,
		isEnergy:false,
		issign:0
	},
	onLoad:function(options){ 

	},
	proTap(e){ 
		let province = e.currentTarget.dataset.province;
		let carnum   = this.data.carnum;
		this.setData({
			carnum:carnum + province,
			hiddenPro:true,
			hiddenStr:false,
			ordinarynum:province,
			energycar:province
		})
	},
	strTap(e){
		let province = e.currentTarget.dataset.str;
		let carnum   = this.data.carnum;	
		if(this.data.isOrdinary){
			if(carnum.length > 6) return; 
		}else{
			if(carnum.length > 7) return; 
		}		
		carnum += province;
		this.setData({
			carnum:carnum,
			ordinarynum:carnum,
			energycar:carnum
		})		
	},
	backSpace(){
		let carnum = this.data.carnum;
		var arr    = carnum.split('');
		arr.splice(-1, 1);
		var str = arr.join('');
		if(str == ''){
			this.setData({
				hiddenPro:false,
				hiddenStr:true				
			})
		}
		this.setData({
			carnum:str,
			ordinarynum:arr,
			energycar:arr
		})
	},
	switchEvent:function(e){
	    this.setData({
	    isOrdinary:(!this.data.isOrdinary),
		    isEnergy:!this.data.isEnergy,
		    ordinarynum:'',
		    energycar:'',
		    carnum:'',
		    hiddenPro:false,
		    hiddenStr:true
	    }) 		  
	},
	checkboxChange:function(e){
		this.setData({ 
			issign:e.detail.value
		}) 
	},
	addPark:function(e){
		if(!this.data.carnum || this.data.carnum.length<7){
			wx.showToast({
			    title:'请输入正确的车牌号',
			    icon:'none'
			})
	    	return false;
		}
		//添加车牌
		app.request('/api/Parking/addCar', {carnum:this.data.carnum,issign:this.data.issign}, function(res){
			if(res.code == '0'){
				//更新数据
				var signurl = res.data.data;
				setTimeout(function(){
					if(signurl){
						wx.redirectTo({
						   url:'/pages/webview/webview?url=' + encodeURIComponent(signurl)
						})
					}else{
						wx.redirectTo({
						   url:'/pages/bindplate/bindplate'
						})
					}
				}, 1500);
			}else{
				wx.showToast({
					title:res.msg,
					icon:'none'
				})
			}
		});
	}
})